#ifndef _CHARSET_H_
#define _CHARSET_H_

#include "../common_define.h"

// 下面代码摘自mysql5的源码，如果字符集发生变化，需要从ctype-xxx.c中找到对应的代码
// 目前只支持GBK和UTF-8两种字符集

/* wm_wc and wc_mb return codes */
#define MY_CS_ILSEQ     0     /* Wrong by sequence: wb_wc                   */
#define MY_CS_ILUNI     0     /* Cannot encode Unicode to charset: wc_mb    */
#define MY_CS_TOOSMALL  -101  /* Need at least one byte:    wc_mb and mb_wc */
#define MY_CS_TOOSMALL2 -102  /* Need at least two bytes:   wc_mb and mb_wc */
#define MY_CS_TOOSMALL3 -103  /* Need at least three bytes: wc_mb and mb_wc */
/* These following three are currently not really used */
#define MY_CS_TOOSMALL4 -104  /* Need at least 4 bytes: wc_mb and mb_wc */
#define MY_CS_TOOSMALL5 -105  /* Need at least 5 bytes: wc_mb and mb_wc */
#define MY_CS_TOOSMALL6 -106  /* Need at least 6 bytes: wc_mb and mb_wc */


/**
 * @brief isgbkhead 判断输入的字符c是否是gbk编码的头部
 *
 * @param c 无符号型字符
 *
 * @return
 */
#define isgbkhead(c) (0x81<=(uchar)(c) && (uchar)(c)<=0xfe)

 /**
  * @brief isgbktail 判断输入字符c是否是gbk编码的尾部
  *
  * @param c 无符号型字符
  *
  * @return
  */
#define isgbktail(c) ((0x40<=(uchar)(c) && (uchar)(c)<=0x7e) || (0x80<=(uchar)(c) && (uchar)(c)<=0xfe))


#ifndef IS_DOUBLE_CHAR
#define IS_DOUBLE_CHAR(ch) ( ch>=0xA0&&ch<0xFF)
#endif


#define USE_MB 1
#define TRUE 1
#define my_wc_t uint64_t
  /**
   * @brief escape_string_for_mysql MYSQL中使用的转义函数
   *
   */
uint64_t escape_string_for_mysql( char *to, uint64_t to_length, const char *from, uint64_t length );


#endif // _CHARSET_H_
